/*
 * =====================================================================================
 *
 *       Filename:  commondef.h
 *
 *    Description:  common struct and fuction definitions.
 *
 *        Version:  1.0
 *        Created:  07/07/2009 02:38:17 PM
 *       Revision:  none
 *       Compiler:  gcc
 *       File Last Modify:$Date: 2009-10-28 21:51:12 +0800 (Wed, 28 Oct 2009) $
 *
 *         Author:  BOYPT (PT), pentie@gmail.com
 *        Company:  http://apt-blog.co.cc
 *
 * =====================================================================================
 */


#ifndef  COMMONDEF_INC
#define  COMMONDEF_INC

#include <pcap.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#include <string.h>
#include <ctype.h>
#include <errno.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/stat.h>

#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <net/ethernet.h>
#ifndef __linux
//------bsd/apple mac
    #include <net/if_var.h>
    #include <net/if_dl.h>
    #include <net/if_types.h>
#endif

#include <getopt.h>

/* ZTE Version */
#define ZTE_VER "0.1"

/* default snap length (maximum bytes per packet to capture) */
#define SNAP_LEN 1518

/* ethernet headers are always exactly 14 bytes [1] */
#define SIZE_ETHERNET 14

#define	OFFSET_EAPOL    0x0E			/*  */
#define OFFSET_EAP      0x12

//#define ETHER_ADDR_LEN 6


struct eap_header {
    u_char eapol_v;//0
    u_char eapol_t;//1
    u_short eapol_length;//2
    u_char eap_t;//4
    u_char eap_id;//5
    u_short eap_length;//6
    u_char eap_op;//8
    u_char eap_v_length;//9
    u_char eap_md5_challenge[16];//10
};

enum EAPOL_TYPE{
	EAPOL_EAP = 0,
	EAPOL_KEY = 3
};

enum EAPType {
    EAPOL_START,
    EAPOL_LOGOFF,
    EAP_REQUEST_IDENTITY,
    EAP_RESPONSE_IDENTITY,
    EAP_REQUEST_IDENTITY_KEEP_ALIVE,
    EAP_RESPONSE_IDENTITY_KEEP_ALIVE,
    EAP_REQUETS_MD5_CHALLENGE,
    EAP_RESPONSE_MD5_CHALLENGE,
    EAP_SUCCESS,
    EAP_FAILURE,
    EAP_KEEP_ALIVE,
    RUIJIE_EAPOL_MSG,
    ERROR
};

enum STATE {
   READY,
   STARTED,
   ID_AUTHED,
   ONLINE,
   STATUS_ERROR
};

typedef union
{
  u_int32_t int_value;
  u_int8_t  byte_value[4];
} BYTEArray;


/* #####   FUNCTION DEFINITIONS  -  EXPORTED FUNCTIONS   ############################ */
/* main.c内实现的函数, 在zruijie.c调用*/
void    daemon_init(void);
//void*   thread_wait_exit (void *arg);

/* #####   FUNCTION DEFINITIONS  -  EXPORTED FUNCTIONS   ############################ */
/* zruijie.c内实现，调用的函数*/
void    init_frames();
void    init_info();
void    init_device();
void    show_local_info();
void    get_packet(u_char *args, const struct pcap_pkthdr *header, 
                        const u_char *packet);
void    print_hex(const uint8_t *array, int count);
#endif   /* ----- #ifndef COMMONDEF_INC  ----- */


